#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
#include <QToolBar>
#include <QTime>
#include <QTimer>
#include <QProgressBar>
#include <QLayout>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    initital();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initital()
{
    setWindowTitle("界面程序-李运泽-2025.04.24");

    initital_menu();

    initital_tool();

    initital_status();

    my_test7 = new test7;   
    ui->stackedWidget->addWidget(my_test7);

    my_test8 = new test8;
    ui->stackedWidget->addWidget(my_test8);

    my_test9 = new test9;
    ui->stackedWidget->addWidget(my_test9);

    my_test13 = new test13;
    ui->stackedWidget->addWidget(my_test13);

    my_test14 = new test14;
    ui->stackedWidget->addWidget(my_test14);

    my_test15 = new test15;
    ui->stackedWidget->addWidget(my_test15);
}

void MainWindow::initital_menu()
{
    QMenuBar *my_menubar = new QMenuBar;
    setMenuBar(my_menubar);
    QMenu *menu_File = new QMenu("文件");
    QMenu *menu_View = new QMenu("视图&v");
    QMenu *menu_Set = new QMenu("设置");
    QMenu *menu_Help = new QMenu("帮助");
    my_menubar->addMenu(menu_File);
    my_menubar->addMenu(menu_View);
    my_menubar->addMenu(menu_Set);
    my_menubar->addMenu(menu_Help);

    QAction *action_open = new QAction("打开新界面&o");
    menu_View->addAction(action_open);

    connect(action_open,&QAction::triggered,this,[=](){
        QWidget *my_widget = new QWidget();
        my_widget->show();
    });
}

void MainWindow::initital_tool()
{
    QToolBar *my_toolbar = new QToolBar;
    addToolBar(my_toolbar);
    for(int i=1;i<6;i++)
    {
        QAction *my_action = new QAction;
        my_action->setIcon(QIcon(":/new/prefix1/res/"+QString::number(i)+".png"));
        my_toolbar->addAction(my_action);
        connect(my_action,&QAction::triggered,this,[=]()
        {
            QWidget *my_widget = new QWidget();
            my_widget->setStyleSheet("QWidget\n{\n	border-image: url(:/new/prefix1/res/"+QString::number(i)+".png);\n}");
            my_widget->show();
            qDebug()<<QString::number(i);
        });
    }
}

void MainWindow::initital_status()
{

    QStatusBar *my_statusbar = new QStatusBar;
    setStatusBar(my_statusbar);
    QLabel *label_name = new QLabel("李运泽");
    QProgressBar *my_progressbar = new QProgressBar;
    my_progressbar->setMaximum(60);
    my_progressbar->setValue(QTime::currentTime().toString("ss").toInt());
    QLabel *label_time = new QLabel(QTime::currentTime().toString("hh:mm:ss"));
    my_statusbar->addWidget(label_name);
    my_statusbar->addPermanentWidget(label_time);
    my_statusbar->addPermanentWidget(my_progressbar);

    QTimer *timer = new QTimer;
    connect(timer,&QTimer::timeout,this,[=]()
    {
        QTime time = QTime::currentTime();
        label_time->setText(time.toString("hh:mm:ss"));
        my_progressbar->setValue(time.toString("ss").toInt());
    });
    timer->start(500);
}



void MainWindow::on_pushButton_clicked()
{
    ui->stackedWidget->setCurrentWidget(my_test7);
}

void MainWindow::on_pushButton_2_clicked()
{
    ui->stackedWidget->setCurrentWidget(my_test8);
}

void MainWindow::on_pushButton_3_clicked()
{
    ui->stackedWidget->setCurrentWidget(my_test13);
}

void MainWindow::on_pushButton_4_clicked()
{
    ui->stackedWidget->setCurrentWidget(my_test14);
}

void MainWindow::on_pushButton_5_clicked()
{
    ui->stackedWidget->setCurrentWidget(my_test15);
}

void MainWindow::on_pushButton_6_clicked()
{
    ui->stackedWidget->setCurrentWidget(my_test9);
}
